unit Con_Empresa;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DbTables, Formulario_Padrao_Consulta, Grids, DBGrids, StdCtrls,
  Buttons, ExtCtrls, TFlatButtonUnit;

type
  TFrmCon_Empresa = class(TFrmConsulta)
    Label1: TLabel;
    edtNome: TEdit;
    dbgEmpresa: TDBGrid;
    btnGravar: TFlatButton;
    procedure BtnFecharClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure edtNomeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure btnGravarClick(Sender: TObject);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    Emp_Codigo: string;
  end;

var
  FrmCon_Empresa: TFrmCon_Empresa;

implementation
uses Dm, Biblio, clsEmpresa, Cad_Empresa, menu;

{$R *.DFM}

var
  Empresa: TEmpresa;
  tds: Tdatasource;
  tq: Tquery;

procedure TFrmCon_Empresa.BtnFecharClick(Sender: TObject);
begin
  inherited;
  Emp_Codigo := tq.fieldbyname('Emp_Codigo').asstring;
  tds.free;
  tq.free;
end;

procedure TFrmCon_Empresa.FormActivate(Sender: TObject);
begin
  inherited;
  if FileExists(caminho_personal + 'belquimica') then begin
    btnGravar.Visible := False;
  end;
  tds := TDataSource.create(FrmCon_Empresa);
  tq := Tquery.create(FrmCon_Empresa);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  tds.DataSet := tq;
  fazconsulta;
  edtnome.setfocus;
end;

procedure TFrmCon_Empresa.FazConsulta;
begin
  if edtnome.text = '' then
    edtnome.text := ' ';
  Empresa := TEmpresa.Create;
  Empresa.Consultar(tq, edtnome.text);
  tq.open;
  Empresa.free;
  dbgEmpresa.DataSource := tds;
  dbgEmpresa.Refresh;
end;

procedure TFrmCon_Empresa.edtNomeKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if key = 12 then begin
    FazConsulta;
    edtNome.setfocus;
  end;
end;

procedure TFrmCon_Empresa.btnGravarClick(Sender: TObject);
var
  f1: TfrmCad_Empresa;
begin
  inherited;
  f1 := TfrmCad_Empresa.Create(Self);
  f1.btnC_Empresa.Visible := False;
  f1.ShowModal;
  f1.Free;
  FazConsulta;
end;

end.
